package mains;

import java.util.Collection;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import app.Customer;
import app.Merchant;

public class Main3ManyToMany {

    private static final String PERSISTENCE_UNIT_NAME = "CashM";
    private static EntityManagerFactory factory;

    public static void main(String[] args) {
	factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
	EntityManager em = factory.createEntityManager();
	Customer customer = null;
	try {
	    customer = em.find(Customer.class, 2);
	} finally {
	    em.close();
	}
	if (customer != null) {
	    System.out.println(customer.getStringForPrint());
	    Collection<Merchant> merchants = customer.getMerchants();
	    for (Merchant m : merchants) {
		System.out.println(m.getStringForPrint());
	    }
	}
    }

}
